package com.wmh.baseservice.user.controller;

import com.wmh.baseservice.common.utils.UUIDUtil;
import com.wmh.baseservice.common.utils.returnbody.ResultCodeInfo;
import com.wmh.baseservice.common.utils.returnbody.ReturnBody;
import com.wmh.baseservice.user.pojo.UsTopUpWithdrawal;
import com.wmh.baseservice.user.service.UsInfoService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.wmh.baseservice.user.service.UsTopUpWithdrawalService;

import java.math.BigDecimal;

/**
 * @author wmh generator
 * @since 2022-08-27
 */
@Api(tags = "用户端-充值/提现相关接口")
@RestController
@RequestMapping(value = "user/usTopUpWithdrawal", produces = "text/plain;charset=utf-8")
@RequiresRoles("user")
public class UsTopUpWithdrawalController {

    @Resource
    private UsTopUpWithdrawalService usTopUpWithdrawalService;
    @Resource
    private UsInfoService usInfoService;
    @Resource
    private HttpServletRequest request;

    @ApiOperation("充值")
    @PostMapping("topUp")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = Long.class, name = "id", value = "id", required = false),
    })
    public String topUp(BigDecimal money) {
        Long usId = (Long) request.getAttribute("usId");
        UsTopUpWithdrawal usTopUpWithdrawal = new UsTopUpWithdrawal().setUsId(usId).setStatus(-1).setMoney(money).setType(1).setOrderNum(UUIDUtil.getTimeId() + UUIDUtil.getLetter());
        if (!usTopUpWithdrawalService.save(usTopUpWithdrawal)) {
            return ReturnBody.error(ResultCodeInfo.SERVICE_EXCEPTION);
        }
        return ReturnBody.success(usTopUpWithdrawal.getOrderNum());
    }

}
